﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace Tools
{
    public class PrintHelper
    {
        public static void PrintReport(PrintModel model, DataSet ds,string path)
        {
			var fs = new FastReport.Report();
			fs.RegisterData(ds);
			try
			{
				fs.Load(path);
				switch (model)
				{
					case PrintModel.Design:
						fs.Design();
						var arr = path.Split('\\');
						Connect.dbcontext.Deleteable<ReportTable>().Where(x => x.reportName == arr[arr.Length - 1] && x.reportStyle == ReportService.报表).ExecuteCommand();
						ReportService.LoadReport(path, new ReportTable { reportStyle = ReportService.报表, reportName = arr[arr.Length - 1] });
						break;
					case PrintModel.Privew:
						fs.Show();
						break;
					case PrintModel.Print:
						fs.Print();
						break;
				}
			}
			catch
			{
				fs.Design();
				var arr = path.Split('\\');
				Connect.dbcontext.Deleteable<ReportTable>().Where(x => x.reportName == arr[arr.Length - 1] && x.reportStyle == ReportService.报表).ExecuteCommand();
				ReportService.LoadReport(path, new ReportTable { reportStyle = ReportService.报表, reportName = arr[arr.Length - 1] });
			}
		}
    }
}
